package com.iiapk.gridnew.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;

import com.iiapk.gridnew.R;

public class MyView extends LinearLayout implements OnGestureListener{

	GestureDetector gestureDetector;
	boolean flag=false;
	
	public MyView(Context context, AttributeSet attrs) {
		super(context, attrs);
		View view = View.inflate(context,R.layout.list_favorite_item, null);
		addView(view);
		gestureDetector = new GestureDetector(this);
		view.setBackgroundResource(R.drawable.box);
		view.setClickable(true);
	}
	
	MotionEvent e0 = null;
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		 super.onInterceptTouchEvent(ev);
         if(ev.getAction()==MotionEvent.ACTION_DOWN){
        	 e0=MotionEvent.obtain(ev);
             //super.onTouchEvent(ev);
         }else if(ev.getAction()==MotionEvent.ACTION_MOVE){
             if(Math.abs(ev.getX()-e0.getX())>10){
            	 e0=MotionEvent.obtain(ev);
            	 return true;
             }
        	 return false;
         }
         return false;
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		/* if(gestureDetector.onTouchEvent(event))
				 return true;*/
		 return super.onTouchEvent(event);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		Log.v("onDown", "onDown");
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		Log.v("onSingleTapUp", "onSingleTapUp");
		flag=true;
		return false;
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		Log.v("onFling", "onFling");
		return true;
	}
	
	

}
